home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / Tumbler and Podium / Tumbler_ErrorHandler.c < prev    next >
Encoding:
Text File  |  1995-11-13  |  15.0 KB  |  377 lines  |  [TEXT/MPCC]

  1. // qd3d sample code - Nick Thompson DEVSUPPORT, 23rd March 1995
  2. //
  3. // © 1995, Apple Computer Inc., All Rights Reserved
  4. //
  5. #include <Dialogs.h>
  6. #include <Memory.h>
  7. #include <SegLoad.h>
  8. #include <TextUtils.h>
  9.  
  10. #include "QD3D.h"
  11. #include "QD3DErrors.h"
  12.  
  13. #include "Tumbler_ErrorHandler.h"
  14.  
  15.  
  16. //---------------------------------------------------------------------------
  17.  
  18. const int kErrorHandlerAlertID = 21032 ;            // ID of the alert resource
  19.  
  20. //---------------------------------------------------------------------------
  21.  
  22. // THIS ENUM MUST MATCH THE STRUCT BELOW
  23. enum {
  24.     kWarningString,
  25.     kErrorString,
  26.     kFirstErrorString,
  27.     kLastErrorString,
  28.     kSpaceString,
  29.     kOpenParen,
  30.     kCloseParen,
  31.     kUnknownErrorString
  32. } ;
  33.  
  34.  
  35. // use these to construct intelligable messages
  36. static struct {
  37.     Str255        errorString ;
  38. } stringTable[] = {
  39.     "\pQuickDraw 3D warning.\r\r", 
  40.     "\pQuickDraw 3D Error.\r\r",
  41.     "\p\rFirst Error: ",
  42.     "\p\rLast Error: "
  43.     "\p ",
  44.     "\p(",
  45.     "\p)",
  46.     "\p\rUnknown Message"
  47. } ;
  48.  
  49.  
  50. //---------------------------------------------------------------------------
  51.  
  52.  
  53. /*
  54.     To generate these tables, copy/paste the error codes from QD3DErrors.h
  55.     and use this regexp:
  56.     
  57.     Find:        kQ3Error([0-9A-z]*),
  58.     Replace:    kQ3Error\1, "\\pkQ3Error\1",
  59.     
  60.     Find:        kQ3Warning([0-9A-z]*),
  61.     Replace:    kQ3Warning\1, "\\pkQ3Warning\1",
  62.     
  63.     Find:        kQ3Notice([0-9A-z]*),
  64.     Replace:    kQ3Notice\1, "\\pkQ3Notice\1",
  65.     
  66. */
  67.  
  68.  
  69. // define a table for all of the QuickDraw 3D error codes
  70. struct {
  71.     TQ3Warning    theWarning ;
  72.     Str255        theString ;
  73. } warningTable[] = {
  74.     /* General System */
  75.     kQ3WarningInternalException, "\pkQ3WarningInternalException",    
  76.     /* Object Warnings */
  77.     kQ3WarningNoObjectSupportForDuplicateMethod, "\pkQ3WarningNoObjectSupportForDuplicateMethod",
  78.     kQ3WarningNoObjectSupportForDrawMethod, "\pkQ3WarningNoObjectSupportForDrawMethod",
  79.     kQ3WarningNoObjectSupportForWriteMethod, "\pkQ3WarningNoObjectSupportForWriteMethod",
  80.     kQ3WarningNoObjectSupportForReadMethod, "\pkQ3WarningNoObjectSupportForReadMethod",
  81.     kQ3WarningUnknownElementType, "\pkQ3WarningUnknownElementType",
  82.     kQ3WarningTypeAndMethodAlreadyDefined, "\pkQ3WarningTypeAndMethodAlreadyDefined",
  83.     kQ3WarningTypeIsOutOfRange, "\pkQ3WarningTypeIsOutOfRange",
  84.     kQ3WarningTypeHasNotBeenRegistered, "\pkQ3WarningTypeHasNotBeenRegistered",
  85.     /* Parameter Warnings */
  86.     kQ3WarningVector3DNotUnitLength, "\pkQ3WarningVector3DNotUnitLength",
  87.     /* IO Warnings */
  88.     kQ3WarningInvalidSubObjectForObject, "\pkQ3WarningInvalidSubObjectForObject",
  89.     kQ3WarningInvalidHexString, "\pkQ3WarningInvalidHexString",
  90.     kQ3WarningUnknownObject, "\pkQ3WarningUnknownObject",
  91.     kQ3WarningInvalidMetafileObject, "\pkQ3WarningInvalidMetafileObject",
  92.     kQ3WarningUnmatchedBeginGroup, "\pkQ3WarningUnmatchedBeginGroup",
  93.     kQ3WarningUnmatchedEndGroup, "\pkQ3WarningUnmatchedEndGroup",
  94.     kQ3WarningInvalidTableOfContents, "\pkQ3WarningInvalidTableOfContents",
  95.     kQ3WarningUnresolvableReference, "\pkQ3WarningUnresolvableReference",
  96.     kQ3WarningNoAttachMethod, "\pkQ3WarningNoAttachMethod",
  97.     kQ3WarningInconsistentData, "\pkQ3WarningInconsistentData",
  98.     kQ3WarningReadLessThanSize, "\pkQ3WarningReadLessThanSize",
  99.     kQ3WarningFilePointerResolutionFailed, "\pkQ3WarningFilePointerResolutionFailed",
  100.     kQ3WarningFilePointerRedefined, "\pkQ3WarningFilePointerRedefined",
  101.     kQ3WarningStringExceedsMaximumLength, "\pkQ3WarningStringExceedsMaximumLength",
  102.     /* Memory Warnings */
  103.     kQ3WarningLowMemory, "\pkQ3WarningLowMemory",
  104.     kQ3WarningPossibleMemoryLeak, "\pkQ3WarningPossibleMemoryLeak",
  105.     /* View Warnings */
  106.     kQ3WarningViewTraversalInProgress, "\pkQ3WarningViewTraversalInProgress",
  107.     kQ3WarningNonInvertibleMatrix, "\pkQ3WarningNonInvertibleMatrix",
  108.     /* Quaternion Warning */
  109.     kQ3WarningQuaternionEntriesAreZero, "\pkQ3WarningQuaternionEntriesAreZero",
  110.     /* Renderer Warning */
  111.     kQ3WarningFunctionalityNotSupported, "\pkQ3WarningFunctionalityNotSupported",
  112.     /* DrawContext Warning */
  113.     kQ3WarningInvalidPaneDimensions, "\pkQ3WarningInvalidPaneDimensions",
  114.     /* Pick Warning */
  115.     kQ3WarningPickParamOutside, "\pkQ3WarningPickParamOutside",
  116.     /* Scale Warnings */
  117.     kQ3WarningScaleEntriesAllZero, "\pkQ3WarningScaleEntriesAllZero",
  118.     kQ3WarningScaleContainsNegativeEntries, "\pkQ3WarningScaleContainsNegativeEntries",
  119.     /* Generic Warnings */
  120.     kQ3WarningParameterOutOfRange, "\pkQ3WarningParameterOutOfRange"
  121. } ;
  122.  
  123.  
  124. struct {
  125.     TQ3Error    theError ;
  126.     Str255        theString ;
  127. } errorTable[] = {
  128.     /* Fatal Errors */
  129.     kQ3ErrorInternalError, "\pkQ3ErrorInternalError",
  130.     kQ3ErrorNoRecovery, "\pkQ3ErrorNoRecovery",                    /* TODO: This is not used correctly */
  131.     kQ3ErrorLastFatalError, "\pkQ3ErrorLastFatalError",
  132.     /* System Errors */
  133.     kQ3ErrorNotInitialized, "\pkQ3ErrorNotInitialized",
  134.     kQ3ErrorAlreadyInitialized, "\pkQ3ErrorAlreadyInitialized",
  135.     kQ3ErrorUnimplemented, "\pkQ3ErrorUnimplemented",
  136.     kQ3ErrorRegistrationFailed, "\pkQ3ErrorRegistrationFailed",
  137.     /* OS Errors */
  138.     kQ3ErrorUnixError, "\pkQ3ErrorUnixError",
  139.     kQ3ErrorMacintoshError, "\pkQ3ErrorMacintoshError",
  140.     kQ3ErrorX11Error, "\pkQ3ErrorX11Error",
  141.     /* Memory Errors */
  142.     kQ3ErrorMemoryLeak, "\pkQ3ErrorMemoryLeak",
  143.     kQ3ErrorOutOfMemory, "\pkQ3ErrorOutOfMemory",
  144.     /* Parameter errors */
  145.     kQ3ErrorNULLParameter, "\pkQ3ErrorNULLParameter",
  146.     kQ3ErrorParameterOutOfRange, "\pkQ3ErrorParameterOutOfRange",
  147.     kQ3ErrorInvalidParameter, "\pkQ3ErrorInvalidParameter",            /* TODO: Make this more specific */
  148.     kQ3ErrorInvalidData, "\pkQ3ErrorInvalidData",                /* TODO: Is this used? */
  149.     kQ3ErrorAcceleratorAlreadySet, "\pkQ3ErrorAcceleratorAlreadySet",        /* TODO: Is this used? */
  150.     kQ3ErrorVector3DNotUnitLength, "\pkQ3ErrorVector3DNotUnitLength",
  151.     kQ3ErrorVector3DZeroLength, "\pkQ3ErrorVector3DZeroLength",
  152.     /* Object Errors */
  153.     kQ3ErrorInvalidObject, "\pkQ3ErrorInvalidObject",
  154.     kQ3ErrorInvalidObjectClass, "\pkQ3ErrorInvalidObjectClass",
  155.     kQ3ErrorInvalidObjectType, "\pkQ3ErrorInvalidObjectType",
  156.     kQ3ErrorInvalidObjectName, "\pkQ3ErrorInvalidObjectName",
  157.     kQ3ErrorObjectClassInUse, "\pkQ3ErrorObjectClassInUse",            
  158.     kQ3ErrorAccessRestricted, "\pkQ3ErrorAccessRestricted",
  159.     kQ3ErrorMetaHandlerRequired, "\pkQ3ErrorMetaHandlerRequired",
  160.     kQ3ErrorNeedRequiredMethods, "\pkQ3ErrorNeedRequiredMethods",
  161.     kQ3ErrorNoSubClassType, "\pkQ3ErrorNoSubClassType",
  162.     kQ3ErrorUnknownElementType, "\pkQ3ErrorUnknownElementType",
  163.     kQ3ErrorNotSupported, "\pkQ3ErrorNotSupported",
  164.     /* Extension Errors */
  165.     kQ3ErrorNoExtensionsFolder, "\pkQ3ErrorNoExtensionsFolder",
  166.     kQ3ErrorExtensionError, "\pkQ3ErrorExtensionError",
  167.     kQ3ErrorPrivateExtensionError, "\pkQ3ErrorPrivateExtensionError",
  168.     /* Geometry Errors */
  169.     kQ3ErrorDegenerateGeometry, "\pkQ3ErrorDegenerateGeometry",
  170.     kQ3ErrorGeometryInsufficientNumberOfPoints, "\pkQ3ErrorGeometryInsufficientNumberOfPoints",
  171.     /* IO Errors */
  172.     kQ3ErrorNoStorageSetForFile, "\pkQ3ErrorNoStorageSetForFile",
  173.     kQ3ErrorEndOfFile, "\pkQ3ErrorEndOfFile",
  174.     kQ3ErrorFileCancelled, "\pkQ3ErrorFileCancelled",
  175.     kQ3ErrorInvalidMetafile, "\pkQ3ErrorInvalidMetafile",
  176.      kQ3ErrorInvalidMetafilePrimitive, "\pkQ3ErrorInvalidMetafilePrimitive",
  177.      kQ3ErrorInvalidMetafileLabel, "\pkQ3ErrorInvalidMetafileLabel",
  178.      kQ3ErrorInvalidMetafileObject, "\pkQ3ErrorInvalidMetafileObject",
  179.      kQ3ErrorInvalidMetafileSubObject, "\pkQ3ErrorInvalidMetafileSubObject",
  180.     kQ3ErrorInvalidSubObjectForObject, "\pkQ3ErrorInvalidSubObjectForObject",
  181.     kQ3ErrorUnresolvableReference, "\pkQ3ErrorUnresolvableReference",
  182.     kQ3ErrorUnknownObject, "\pkQ3ErrorUnknownObject",
  183.     kQ3ErrorStorageInUse, "\pkQ3ErrorStorageInUse",
  184.     kQ3ErrorStorageAlreadyOpen, "\pkQ3ErrorStorageAlreadyOpen",
  185.     kQ3ErrorStorageNotOpen, "\pkQ3ErrorStorageNotOpen",
  186.     kQ3ErrorStorageIsOpen, "\pkQ3ErrorStorageIsOpen",
  187.     kQ3ErrorFileAlreadyOpen, "\pkQ3ErrorFileAlreadyOpen",
  188.     kQ3ErrorFileNotOpen, "\pkQ3ErrorFileNotOpen",
  189.     kQ3ErrorFileIsOpen, "\pkQ3ErrorFileIsOpen",
  190.     kQ3ErrorBeginWriteAlreadyCalled, "\pkQ3ErrorBeginWriteAlreadyCalled",
  191.     kQ3ErrorBeginWriteNotCalled, "\pkQ3ErrorBeginWriteNotCalled",
  192.     kQ3ErrorEndWriteNotCalled, "\pkQ3ErrorEndWriteNotCalled",
  193.     kQ3ErrorReadStateInactive, "\pkQ3ErrorReadStateInactive",
  194.     kQ3ErrorStateUnavailable, "\pkQ3ErrorStateUnavailable",
  195.     kQ3ErrorWriteStateInactive, "\pkQ3ErrorWriteStateInactive",
  196.     kQ3ErrorSizeNotLongAligned, "\pkQ3ErrorSizeNotLongAligned",
  197.     kQ3ErrorFileModeRestriction, "\pkQ3ErrorFileModeRestriction",
  198.     kQ3ErrorInvalidHexString, "\pkQ3ErrorInvalidHexString",
  199.     kQ3ErrorWroteMoreThanSize, "\pkQ3ErrorWroteMoreThanSize",
  200.     kQ3ErrorWroteLessThanSize, "\pkQ3ErrorWroteLessThanSize",
  201.     kQ3ErrorReadLessThanSize, "\pkQ3ErrorReadLessThanSize",
  202.     kQ3ErrorReadMoreThanSize, "\pkQ3ErrorReadMoreThanSize",
  203.     kQ3ErrorNoBeginGroup, "\pkQ3ErrorNoBeginGroup",
  204.     kQ3ErrorSizeMismatch, "\pkQ3ErrorSizeMismatch",
  205.     kQ3ErrorStringExceedsMaximumLength, "\pkQ3ErrorStringExceedsMaximumLength",
  206.     kQ3ErrorValueExceedsMaximumSize, "\pkQ3ErrorValueExceedsMaximumSize",
  207.     kQ3ErrorNonUniqueLabel, "\pkQ3ErrorNonUniqueLabel",
  208.     kQ3ErrorEndOfContainer, "\pkQ3ErrorEndOfContainer",
  209.     kQ3ErrorUnmatchedEndGroup, "\pkQ3ErrorUnmatchedEndGroup",
  210.     kQ3ErrorFileVersionExists, "\pkQ3ErrorFileVersionExists",
  211.     /* View errors */
  212.     kQ3ErrorViewNotStarted, "\pkQ3ErrorViewNotStarted",
  213.     kQ3ErrorViewIsStarted, "\pkQ3ErrorViewIsStarted",
  214.     kQ3ErrorRendererNotSet, "\pkQ3ErrorRendererNotSet",
  215.     kQ3ErrorRenderingIsActive, "\pkQ3ErrorRenderingIsActive",
  216.     kQ3ErrorImmediateModeUnderflow, "\pkQ3ErrorImmediateModeUnderflow",
  217.     kQ3ErrorDisplayNotSet, "\pkQ3ErrorDisplayNotSet",
  218.     kQ3ErrorCameraNotSet, "\pkQ3ErrorCameraNotSet",
  219.     kQ3ErrorDrawContextNotSet, "\pkQ3ErrorDrawContextNotSet",
  220.     kQ3ErrorNonInvertibleMatrix, "\pkQ3ErrorNonInvertibleMatrix",
  221.     kQ3ErrorRenderingNotStarted, "\pkQ3ErrorRenderingNotStarted",
  222.     kQ3ErrorPickingNotStarted, "\pkQ3ErrorPickingNotStarted",
  223.     kQ3ErrorBoundsNotStarted, "\pkQ3ErrorBoundsNotStarted",
  224.     kQ3ErrorDataNotAvailable, "\pkQ3ErrorDataNotAvailable",
  225.     kQ3ErrorNothingToPop, "\pkQ3ErrorNothingToPop",
  226.     /* Renderer Errors */
  227.     kQ3ErrorUnknownStudioType, "\pkQ3ErrorUnknownStudioType",            /* TODO Name Change */
  228.     kQ3ErrorAlreadyRendering, "\pkQ3ErrorAlreadyRendering",
  229.     kQ3ErrorStartGroupRange, "\pkQ3ErrorStartGroupRange",
  230.     kQ3ErrorUnsupportedGeometryType, "\pkQ3ErrorUnsupportedGeometryType",
  231.     kQ3ErrorInvalidGeometryType, "\pkQ3ErrorInvalidGeometryType",
  232.     kQ3ErrorUnsupportedFunctionality, "\pkQ3ErrorUnsupportedFunctionality",
  233.     /* Group Errors */
  234.     kQ3ErrorInvalidPositionForGroup, "\pkQ3ErrorInvalidPositionForGroup",
  235.     kQ3ErrorInvalidObjectForGroup, "\pkQ3ErrorInvalidObjectForGroup",
  236.     kQ3ErrorInvalidObjectForPosition, "\pkQ3ErrorInvalidObjectForPosition",
  237.     /* Transform Errors */
  238.     kQ3ErrorScaleOfZero, "\pkQ3ErrorScaleOfZero",                /* Transform errors? */
  239.     /* String Errors */
  240.     kQ3ErrorBadStringType, "\pkQ3ErrorBadStringType",                /* What is this? */
  241.     /* Attribute Errors */
  242.     kQ3ErrorAttributeNotContained, "\pkQ3ErrorAttributeNotContained",        /* What is this? */
  243.     kQ3ErrorAttributeInvalidType, "\pkQ3ErrorAttributeInvalidType",        /* What is this? */
  244.     /* Camera Errors */
  245.     kQ3ErrorInvalidCameraValues, "\pkQ3ErrorInvalidCameraValues",        /* Redundant with kQ3ErrorParameterOutOfRange */
  246.     /* DrawContext Errors */
  247.     kQ3ErrorBadDrawContextType, "\pkQ3ErrorBadDrawContextType",
  248.     kQ3ErrorBadDrawContextFlag, "\pkQ3ErrorBadDrawContextFlag",
  249.     kQ3ErrorBadDrawContext, "\pkQ3ErrorBadDrawContext",
  250.     kQ3ErrorUnsupportedPixelDepth, "\pkQ3ErrorUnsupportedPixelDepth"
  251. } ;
  252.  
  253.  
  254.  
  255.  
  256. static void ConcatenateString( Str255 firstString, Str255 addThis ) ;
  257. static void CopyString( Str255 firstString, Str255 fromThis ) ;
  258. static void PresentErrMsgInDialog( Str255 theError ) ;
  259.  
  260.  
  261. //-------------------------------------------------------------------------------------------
  262. // MyErrorHandler - handle warnings from QuickDraw 3d
  263. void MyErrorHandler( TQ3Error sticky, TQ3Error latest, long refCon )
  264. {
  265.  
  266. // we only want to do this stuff if we are debugging
  267. #if defined( DEBUGGING_MODE ) && DEBUGGING_MODE
  268.  
  269.     Str255     myErrorStr ;
  270.     Str255    theWholeString ;
  271.  
  272.     short    stickyIndex = sticky - kQ3ErrorInternalError ;
  273.     short    latestIndex = latest - kQ3ErrorInternalError ;
  274.     
  275.     // if the error is out of range, then just tell us that something
  276.     // "unknown" happened. Otherwise look up the error from the table.
  277.     if( sticky != kQ3ErrorNone && ( sticky < kQ3ErrorInternalError || sticky > kQ3ErrorLastError )) {
  278.         CopyString(    theWholeString, stringTable[kErrorString].errorString  ) ;
  279.         ConcatenateString( theWholeString, stringTable[ kUnknownErrorString ].errorString ) ;
  280.     }
  281.     else {
  282.         
  283.         
  284.         CopyString(    theWholeString, stringTable[ kErrorString ].errorString  ) ;
  285.         
  286.         ConcatenateString( theWholeString, stringTable[ kFirstErrorString ].errorString ) ;
  287.         CopyString(    myErrorStr, errorTable[ stickyIndex ].theString) ;
  288.         ConcatenateString( theWholeString, myErrorStr) ;
  289.         
  290.         ConcatenateString( theWholeString, stringTable[ kLastErrorString ].errorString ) ;
  291.         CopyString(    myErrorStr, errorTable[ stickyIndex ].theString) ;
  292.         ConcatenateString( theWholeString, myErrorStr) ;
  293.         
  294.         
  295.         // and display the error string 
  296.         PresentErrMsgInDialog( theWholeString ) ;        
  297.     }
  298.     
  299.     // clear down the error
  300.     latest = Q3Error_Get( &sticky );
  301. #endif
  302.     
  303. }
  304.  
  305.  
  306. //-------------------------------------------------------------------------------------------
  307. // MyErrorHandler - handle warnings from QuickDraw 3d
  308. void MyWarningHandler( TQ3Warning     sticky, TQ3Warning     latest, long refCon )
  309. {
  310.  
  311. // we only want to do this stuff if we are debugging
  312. #if defined( DEBUGGING_MODE ) && DEBUGGING_MODE
  313.  
  314.     Str255     myWarningStr ;
  315.     Str255    theWholeString ;
  316.  
  317.     short    stickyIndex = sticky - kQ3WarningInternalException ;
  318.     short    latestIndex = latest - kQ3WarningInternalException ;
  319.     
  320.     // if the error is out of range, then just tell us that something
  321.     // "unknown" happened. Otherwise look up the error from the table.
  322.     if( sticky != kQ3ErrorNone && ( sticky < kQ3WarningInternalException || sticky > kQ3WarningLastWarning )) {
  323.     
  324.         CopyString(    theWholeString, stringTable[ kWarningString ].errorString  ) ;
  325.         ConcatenateString( theWholeString, stringTable[ kUnknownErrorString ].errorString ) ;
  326.         
  327.     }
  328.     else {
  329.         
  330.         CopyString(    theWholeString, stringTable[ kWarningString ].errorString  ) ;
  331.         
  332.         ConcatenateString( theWholeString, stringTable[ kFirstErrorString ].errorString ) ;
  333.         CopyString(    myWarningStr, warningTable[ stickyIndex ].theString) ;
  334.         ConcatenateString( theWholeString, myWarningStr) ;
  335.         
  336.         ConcatenateString( theWholeString, stringTable[ kLastErrorString ].errorString ) ;
  337.         CopyString(    myWarningStr, warningTable[ stickyIndex ].theString) ;
  338.         ConcatenateString( theWholeString, myWarningStr) ;
  339.         
  340.         // and display the error string 
  341.         PresentErrMsgInDialog( theWholeString ) ;        
  342.     }
  343.     
  344.     // clear down the error
  345.     latest = Q3Warning_Get( &sticky );
  346.     
  347. #endif
  348.  
  349. }
  350.  
  351. //------------------------------------------------------------------------
  352. static void ConcatenateString( Str255 firstString, Str255 addThis )
  353. {
  354.     BlockMove( &addThis[1], &firstString[firstString[0]+1], addThis[0] ) ;
  355.     firstString[0] += addThis[0] ;
  356. }
  357.  
  358.  
  359. //------------------------------------------------------------------------
  360. static void CopyString( Str255 firstString, Str255 fromThis )
  361. {
  362.     BlockMove( &fromThis[1], &firstString[1], fromThis[0] ) ;
  363.     firstString[0] = fromThis[0] ;
  364. }
  365.  
  366. //------------------------------------------------------------------------
  367.  
  368. static void PresentErrMsgInDialog( Str255 theError )
  369. {    
  370.     short    itemHit ;
  371.     ParamText( theError, 0L,  0L,  0L ) ;
  372.     itemHit = StopAlert( kErrorHandlerAlertID, nil ) ;
  373.     
  374.     if( itemHit != ok ) 
  375.         ExitToShell() ;
  376. }
  377.